<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="java.io.*" %>
<%@ page import="com.zll.framework.conf.Configuration" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%
	System.out.println(Configuration.get("temp.dir"));
	int sizeLimit 				= 10 * 1024 * 1024 ; // 5메가까지 제한 넘어서면 예외발생

	MultipartRequest multi		= new MultipartRequest(request, Configuration.get("temp.dir"), sizeLimit, "utf-8", new DefaultFileRenamePolicy());


	//String filename = multi.getFilesystemName("FileData");
	String sDir = multi.getParameter("dir");


	File f = multi.getFile("Filedata");

	//webroot/images/editor/[sDir]/YYYYMMDD1214127236.jpg
	File dir = new File(Configuration.getHomePath() + File.separator + "images" + File.separator + "editor" + File.separator + sDir);
	if (!dir.isDirectory()) {
		dir.mkdir();
	}

	String filename = f.getName();
	String fileExt = filename.substring(filename.lastIndexOf('.'));


	//파일 저장경로 변경
	File moveFile = new File(dir.getAbsolutePath() + File.separator + StringUtil.getFileName()+fileExt);
	f.renameTo(moveFile);


	filename = moveFile.getName();

	if ("".equals(filename)) {
		//이미지를 선택해주세요.
	}
	else {
		out.print(request.getParameter("htImageInfo"));
	}

	String url = multi.getParameter("callback") + "?callback_func=" + multi.getParameter("callback_func");
	url += "&bNewLine=true";
	url += "&sFileName=" + filename;
	url += "&sFileURL=../images/editor/" + sDir + "/" + filename;

	response.sendRedirect(url);
%>